/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package replic.commons.jdbc;

import java.io.Serializable;
import java.util.List;

/**
 *
 * @author Leonardo Oliveira Moreira
 * 
 * This class represents the object of communication between pairs of the system
 */
public class Message implements Serializable {

    public static final int SQL_UPDATE = 1;
    public static final int SQL_COMMIT = 2;
    public static final int SQL_ROLLBACK = 3;
    public static final int SQL_STATEMENT_CREATE = 4;
    public static final int SQL_STATEMENT_CLOSE = 5;
    public static final int SQL_CONNECTION_CREATE = 6;
    public static final int SQL_CONNECTION_CLOSE = 7;
    public static final int SQL_RESULTSET_CREATE = 8;
    public static final int SQL_RESULTSET_CLOSE = 9;
    public static final int STATE_SUCCESS = 10;
    public static final int STATE_FAILURE = 11;
    private String vmName;
    private long startTime;
    private long finishTime;
    private long sqlResponseTime;
    private long sqlAffectedLines;
    private String database;
    private String sql;
    private int sqlType;
    private List<Row> resultSetList = null;
    private int state;
    private long statementID;
    private long connectionID;
    private long resultSetID;

    /**
     * Method that retrieves the connection identifier
     * 
     * @return 
     */
    public long getConnectionID() {
        return connectionID;
    }

    /**
     * Method that sets the connection identifier
     * 
     * @param connectionID 
     */
    public void setConnectionID(long connectionID) {
        this.connectionID = connectionID;
    }

    /**
     * Method that retrieves the statement identifier
     * 
     * @return 
     */
    public long getStatementID() {
        return statementID;
    }

    /**
     * Method that sets the statement identifier
     * 
     * @param statementID 
     */
    public void setStatementID(long statementID) {
        this.statementID = statementID;
    }

    /**
     * Method that retrieves the result set identifier
     * 
     * @return 
     */
    public long getResultSetID() {
        return resultSetID;
    }

    /**
     * Method that sets the result set identifier
     * 
     * @param resultSetID 
     */
    public void setResultSetID(long resultSetID) {
        this.resultSetID = resultSetID;
    }

    /**
     * Method that retrieves the execution status of this message
     * 
     * @return 
     */
    public int getState() {
        return state;
    }

    /**
     * Method that sets the execution status of this message
     * 
     * @param state 
     */
    public void setState(int state) {
        this.state = state;
    }

    /**
     * Method that retrieves the list of lines found by the SQL query in this message
     * 
     * @return 
     */
    public List<Row> getResultSetList() {
        return resultSetList;
    }

    /**
     * Method that sets the list of lines found by the SQL query in this message
     * 
     * @param resultSetList 
     */
    public void setResultSetList(List<Row> resultSetList) {
        this.resultSetList = resultSetList;
    }

    /**
     * Method that retrieves the virtual machine name target for execution of this message
     * 
     * @return 
     */
    public String getVmName() {
        return vmName;
    }

    /**
     * Method that sets the virtual machine name target for execution of this message
     * 
     * @param vmName 
     */
    public void setVmName(String vmName) {
        this.vmName = vmName;
    }

    /**
     * Method that retrieves the sql type of request for execution of this message
     * 
     * @return 
     */
    public int getSqlType() {
        return sqlType;
    }

    /**
     * Method that sets the sql type of request for execution of this message
     * 
     * @param sqlType 
     */
    public void setSqlType(int sqlType) {
        this.sqlType = sqlType;
    }

    /**
     * Method that retrieves the database name target for execution of this message
     * 
     * @return 
     */
    public String getDatabase() {
        return database;
    }

    /**
     * Method that sets the database name target for execution of this message
     * 
     * @param database 
     */
    public void setDatabase(String database) {
        this.database = database;
    }

    /**
     * Method that retrieves the start time of the message
     * 
     * @return 
     */
    public long getStartTime() {
        return startTime;
    }

    /**
     * Method that sets the start time of the message
     * 
     * @param startTime 
     */
    public void setStartTime(long startTime) {
        this.startTime = startTime;
    }

    /**
     * Method that retrieves the finish time of the message
     * 
     * @return 
     */
    public long getFinishTime() {
        return finishTime;
    }

    /**
     * Method that sets the finish time of the message
     * 
     * @param finishTime 
     */
    public void setFinishTime(long finishTime) {
        this.finishTime = finishTime;
    }

    /**
     * Method that retrieves the number of rows affected by the execution of this message
     * 
     * @return 
     */
    public long getSqlAffectedLines() {
        return sqlAffectedLines;
    }

    /**
     * Method that sets the number of rows affected by the execution of this message
     * 
     * @param sqlAffectedLines 
     */
    public void setSqlAffectedLines(long sqlAffectedLines) {
        this.sqlAffectedLines = sqlAffectedLines;
    }

    /**
     * Method that retrieves the local response time of the message
     * 
     * @return 
     */
    public long getSqlResponseTime() {
        return sqlResponseTime;
    }

    /**
     * Method that sets the local response time of the message
     * 
     * @param sqlResponseTime 
     */
    public void setSqlResponseTime(long sqlResponseTime) {
        this.sqlResponseTime = sqlResponseTime;
    }

    /**
     * Method that retrieves the SQL statement for execution of this message
     * 
     * @return 
     */
    public String getSql() {
        return sql;
    }

    /**
     * Method that sets the SQL statement for execution of this message
     * 
     * @param sql 
     */
    public void setSql(String sql) {
        this.sql = sql;
    }

    /**
     * Method for generating a string with the main content of this object
     * 
     * @return 
     */
    @Override
    public String toString() {
        String state = "";
        switch (this.getState()) {
            case Message.STATE_SUCCESS: {
                state = "SUCCESS";
                break;
            }
            case Message.STATE_FAILURE: {
                state = "FAILURE";
                break;
            }
        }
        String sqlType = "";
        switch (this.getSqlType()) {
            case Message.SQL_UPDATE: {
                sqlType = "UPDATE";
                break;
            }
            case Message.SQL_COMMIT: {
                sqlType = "COMMIT";
                break;
            }
            case Message.SQL_ROLLBACK: {
                sqlType = "ROLLBACK";
                break;
            }
            case Message.SQL_CONNECTION_CREATE: {
                sqlType = "CREATE CONNECTION";
                break;
            }
            case Message.SQL_CONNECTION_CLOSE: {
                sqlType = "CLOSE CONNECTION";
                break;
            }
            case Message.SQL_STATEMENT_CREATE: {
                sqlType = "CREATE STATEMENT";
                break;
            }
            case Message.SQL_STATEMENT_CLOSE: {
                sqlType = "CLOSE STATEMENT";
                break;
            }
            case Message.SQL_RESULTSET_CREATE: {
                sqlType = "CREATE RESULTSET";
                break;
            }
            case Message.SQL_RESULTSET_CLOSE: {
                sqlType = "CLOSE RESULTSET";
                break;
            }
        }
        return "Message{" + "vmName=" + vmName + ", sqlResponseTime=" + sqlResponseTime + ", sqlAffectedLines=" + sqlAffectedLines + ", database=" + database + ", sql=" + sql + ", sqlType=" + sqlType + ", state=" + state + '}';
    }
}